import Vue from 'vue'
import VueRouter from 'vue-router'
// import { component } from 'vue/types/umd'

Vue.use(VueRouter)

const routes = [{
    path: "/",
    redirect: "/city"
  },
  {
    path: "/home",
    component: () => import("../views/home/MyHome.vue"),
    children: [{
        path: "takeout/:geohash?",
        component: () => import("../views/xhome/MyTakeout.vue")
      },
      {
        path: "home",
        component: () => import("../views/home/home.vue")
      },
      {
        path: "search",
        component: () => import("../views/xhome/MySearch.vue")
      },
      {
        path: "order",
        component: () => import("../views/xhome/MyOrder.vue")
      },
      {
        path: "user",
        component: () => import("../views/MyUser/MyUser.vue"),
      },
      {
        path: "info",
        component: () => import("../views/MyUser/info/index.vue")
      },
      {
        path: "download",
        component: () => import("../views/download/Download.vue")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("../views/login")
  },
  {
    path: "/forget",
    component: () => import("../views/forget")
  },
  {
    path: "/category",
    component: () => import("../views/category/Category.vue")
  },
  {
    path: "/address",
    component: () => import("../views/info/chilidren/AddAddress.vue")
  },
  {
    path: "/city",
    component: () => import("../views/city/CityList.vue")
  },
  {
    path: "/city/:cityid",
    component: () => import("../views/city/sortgroupcity")
  },

  {
    path: '/confirmOrder/:id',
    component: () => import("../views/confirmOrder/ConfirmOrder.vue")

  },
  {
    path: '/confirmOrder/:id/payment',
    component: () => import('../views/payMent/PayMent.vue')
  },
  {
    //新增地址页
    path: "/info",
    component: () => import("../views/info/Index.vue"),
  },
   {
    //店铺页
    path: "/shop/:id",
    component: () => import("../views/shop/Shop.vue"),
    children: [{
        redirect: 'goods',
        path: ''
      },
      {
        path: 'goods',
        component: () => import("../views/shop/children/Goods.vue")
      },
      {
        path: 'comments',
        component: () => import("../views/shop/children/Comments.vue")
      }
    ]
  }

]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  switch (to.path) {
    case "/home/takeout":
      localStorage.setItem("active", "0")
      break;
    case "/home/search":
      localStorage.setItem("active", "1")
      break;
    case "/home/order":
      localStorage.setItem("active", "2")
      break;
    case "/home/user":
      localStorage.setItem("active", "3")
      break;
  }
  next()
})

export default router